
<?
header("Content-type:text/html;charset=utf-8");
include("common/header.html");
include("/var/www/html/new/conf/yd.le.je");
$ydle=new yd_go_sql();
$ydle->connect(); 
//保存图片 记录图片地址 存入数据库 最后跳转到刚才写的游记页面游记
$ph = $_FILES['photo'];
if($ph){
if($_SERVER['REQUEST_METHOD']!=="POST"){
	echo "<script>alert(\"传输类型不是POST!\");</script>";
	echo "<script language=\"javascript\">";
	echo "document.location=\"".$GLOBALS['_SERVER']['HTTP_REFERER']."\"";
	echo "</script>";
	exit;
}
/*if(!$ph['size']){
	echo "<script>alert(\"没有上传文件!\");</script>";
	echo "<script language=\"javascript\">";
	echo "document.location=\"".$GLOBALS['_SERVER']['HTTP_REFERER']."\"";
	echo "</script>";
	exit;
}
if(count($ph['name'])<3){
	echo "<script>alert(\"上传图片的数量不能少于3张!\");</script>";
	echo "<script language=\"javascript\">";
	echo "document.location=\"".$GLOBALS['_SERVER']['HTTP_REFERER']."\"";
	echo "</script>";
	exit;
	}*/
$type=array("image/gif","image/jpeg","image/pjpeg","image/png","image/x-png");
foreach ($ph['type'] as  $value) {	
	if(!in_array($value,$type)){
	echo "<script>alert(\"上传文件类型不合法!\");</script>";
	echo "<script language=\"javascript\">";
	echo "document.location=\"".$GLOBALS['_SERVER']['HTTP_REFERER']."\"";
	echo "</script>";
	exit;
	}
}
$maxsize=2000000;
foreach ($ph['size'] as  $value) {
	if($value>$maxsize){
	echo "<script>alert(\"上传文件过大!\");</script>";
	echo "<script language=\"javascript\">";
	echo "document.location=\"".$GLOBALS['_SERVER']['HTTP_REFERER']."\"";
	echo "</script>";
	exit;
	}
}
foreach ($ph['error'] as  $value) {	
	if($value>0){
	echo "<script>alert(\"".$value."\");</script>";
	echo "<script language=\"javascript\">";
	echo "document.location=\"".$GLOBALS['_SERVER']['HTTP_REFERER']."\"";
	echo "</script>";
	exit;
	}
}
//按帐号来设置放图片的路径
$passport=$_SESSION['account'];
$dir="yd_prodimgs/".$passport;
if(!is_dir($dir)){//没有上传过图片的话先建目录
	mkdir($dir);
}					
$fulldir=array();
$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
for ($i=0; $i < count($ph['name']); $i++) { 	
	if($ph['name'][$i]){						
        $filename=time().$strPol[rand(0,61)].$strPol[rand(0,61)];//用时间戳和随机数来改写图片名称
        $houzui=strrchr($ph['name'][$i],'.');							
        $fulldir[$i]="yd_prodimgs/".$passport."/".$filename.$houzui;//完整路径
        move_uploaded_file($ph["tmp_name"][$i],$fulldir[$i]);//上传
        }                   
}
// print_r($fulldir);//把数组压缩成一个字符串存进去
$fulldir=implode('|', $fulldir);
}
// print_r($fulldir);
//写入数据库
$id=$_REQUEST['id'];
$topic = $_REQUEST['topic'];
$playtime =$_REQUEST['playtime'];

//echo $playtime;
if($fulldir){
    $pic =$_SESSION['pic'].'|'.$fulldir;
}else{
    $pic =$_SESSION['pic'];
}
$text = $_REQUEST['text'];
//echo $id.$topic.$playtime.$pic.$text;
if($_REQUEST['action']=="发布"){//发布游记
	$sql = "update uu_blog set topic='$topic',playtime='$playtime',pic='$pic',content='$text',status='2' where id=$id";
	$GLOBALS['ydle']->query($sql);
    //  echo "发布成功";
    header("Location:blog.html");
}else if($_REQUEST['action']=="保存"){//保存游记
	$sql = "update uu_blog set topic='$topic',playtime='$playtime',pic='$pic',content='$text' where id=$id";
	$GLOBALS['ydle']->query($sql);
    //echo "保存成功";
    header("Location:blog.html");
}else if($_REQUEST['action']=="取消发布"){
    $sql = "update uu_blog set topic='$topic',playtime='$playtime',pic='$pic',content='$text',status='3' where id=$id";
    $GLOBALS['ydle']->query($sql);
    header("Location:blog.html");
}else if($_REQUEST['action']=="删除"){
    $sql = "update uu_blog set status='4' where id=$id";
    $GLOBALS['ydle']->query($sql);
    // echo "删除成功";
    header("Location:blog.html");
}
exit();
//跳回游记页面
$sql = "SELECT id from uu_blog where fid=$'fid' order by id desc limit 1";
$GLOBALS['ydle']->query($sql);
$GLOBALS['ydle']->fetch_assoc();
$id = $GLOBALS['ydle']->f('id');
echo "<script language=\"javascript\">";
echo "document.location=\"mx.12301.cc/blog.html?id=".$id."\"";
echo "</script>";
?>

